﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // if user already logged in, redirect to Application
        if (!IsPostBack && UserManagement.GetCurrentUsername() != null)
            Response.Redirect("/");
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (UserManagement.UserLoginInfoIsCorrect(txtUsername.Text.Trim(), txtPassword.Text))
        {
            UserManagement.SaveLoginInfoToCookie(txtUsername.Text, chbRememberMe.Checked);
            Response.Redirect("/");
        }
        else
        {
            ltrErrorMessage.Text = "<div id='server_error_message'>Invalid Username or Password for <strong>" + txtUsername.Text + "</strong></div>";
        }
    }
}